package com.example.fw;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;



public class HibernateHelper extends HelperBase {

	public HibernateHelper(ApplicationManager manager) {
	  super(manager);
	}

	public List<User> listUser() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction trans = session.beginTransaction();
		try {
          return ((List<User>)session.createQuery("from User").list());
		} finally {
          trans.commit();
		}
	}
	
	public void deleteUser(User user) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction trans = session.beginTransaction();
		try {
			session.createQuery("DELETE User WHERE login = :login")
		    .setParameter("login", user.login)
		    .executeUpdate();
		} finally {
          trans.commit();
		}
		
		pause(3000);
	}

}
